package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.OrderInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by Administrater on 2015/12/7.
 */
public class BuildOrderTask extends CouponHttpBaseTask {
    private String mvipCommUser;
    private String mObjectId;
    private String mType;
    private String mMoney;
    private String mNextBelong;
    private String mCollege;
    private String mIdentity;
    private String mQuotaId;
    private String mStatue;
    private String mPrivce;
    private String mQuotaSum;


    public BuildOrderTask(String objectId,  String type, String money, String vipCommUser ,String nextBelong,String college,String identity,
                          String quotaId,String status,String privce,String quotaSum) {
        super(TaskType.BUILDORDER_TASK);
        mObjectId = objectId;
        mType = type;
        mMoney = money;
        mvipCommUser = vipCommUser;
        mNextBelong = nextBelong;
        mCollege = college;
        mIdentity = identity;
        mQuotaId = quotaId;
        mStatue = status;
        mPrivce = privce;
        mQuotaSum = quotaSum;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject respJson = response.getBody();
        OrderInfo info = null;
        if (respJson != null) {
            info = JSON.parseObject(respJson.toString(), OrderInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, info);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT) {
            CouponHttpRequest request = new CouponHttpRequest(RequestType.BUILDORDER_REQUEST);
            JSONObject json = new JSONObject();
            json.put("objectId", mObjectId);
            json.put("type", mType);
            json.put("money", mMoney);
            json.put("vipCommUser", mvipCommUser);
            json.put("nextBelong", mNextBelong);
            json.put("college", mCollege);
            json.put("identity",mIdentity);
            json.put("quotaId",mQuotaId);
            json.put("status",mStatue);
            json.put("privce",mPrivce);
            json.put("quotaSum",mQuotaSum);
            request.setData(json.toString());
            request.setApiNo(ApiNo.BUILDORDER);
            addRequest(request);
        }
    }
}
